﻿var $url = '/account';

var data = {
    apiUrl: utils.getQueryString('apiUrl'),
    //siteId: utils.getQueryString('siteId'),
    siteId: 0,
    pageLoad: false,
    contents: [],
    pageIndex: 0,
    pageSize: 20,
    sort: 'Id DESC',
    pageCount: 0,
    recordCount: 0,
    state: 0,
    keyword: null
};

var methods = {
    btnDetailsClick: function (studentId) {
        var $this = this;
        utils.openLayer({
            title: '报名详情',
            url: 'enrollLayerSearchUser.html?siteId=' + $this.siteId + "&key=id" + "&keyword=" + studentId + "&apiUrl=" + encodeURIComponent(this.apiUrl)
        });
    },
    btnSearchClick: function () {
        var $this = this;
        $this.pageIndex = 0;
        $this.loadPage(0);
    },
    loadPage: function (pageIndex) {
        var $this = this;

        var where = "";
        if (!($this.keyword === null || $this.keyword === "")) {
            //where = " AND Mobile = '" + $this.keyword + "' OR DisplayName Like '%25" + $this.keyword + "%25' OR SettingsXml Like '%25" + $this.keyword + "%25'";
            where = $this.keyword;
        }

        $api.get($url + "?where=" + where, {
            params: {
                siteId: this.siteId,
                pageIndex: this.pageIndex,
                pageSize: this.pageSize,
                sort: this.sort
            }
        }).then(function (response) {
            //获取报名
            $this.pageLoad = true;
            $this.contents = response.data.result;
            var length = response.data.count;
            $this.recordCount = length;
            $this.pageCount = length % $this.pageSize === 0 ? parseInt(length / $this.pageSize) : parseInt(length / $this.pageSize) + 1;
        });
    },
    loadFirstPage: function () {
        var $this = this;
        $this.pageIndex = 0;
        $this.loadPage(0);
    },
    loadPrevPage: function () {
        var $this = this;
        if ($this.pageIndex > 0) {
            $this.pageIndex = $this.pageIndex - 1;
            $this.loadPage($this.pageIndex);
        }
    },
    loadNextPage: function () {
        var $this = this;
        if ($this.pageIndex < $this.pageCount - 1) {
            $this.pageIndex = $this.pageIndex + 1;
            $this.loadPage($this.pageIndex);
        }

    },
    loadLastPage: function () {
        var $this = this;

        $this.pageIndex = $this.pageCount - 1;
        $this.loadPage($this.pageIndex);
    }
};

var $vue = new Vue({
    el: '#main',
    data: data,
    methods: methods,
    computed: {

    },
    created: function () {
        this.loadPage(0);
    }
});